<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep  :multi="true" v-model="queryParam.proposer"></select-user-by-dep>
<!--              <a-input placeholder="请输入申请人" v-model="queryParam.proposer"></a-input>-->
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
<!--            <a-form-item label="申请车辆">-->
<!--              <a-input placeholder="请输入申请车辆" v-model="queryParam.applicationCar"></a-input>-->
<!--            </a-form-item>-->
            <a-form-item label="申请车辆">
<!--              <select-car-num-input placeholder="请选择车牌号" v-model="queryParam.applicationCar"/>-->
              <SelectCarInfoInput placeholder="请选择车牌号" :multi="true" v-model="queryParam.applicationCar"/>
            </a-form-item>
          </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="费用所属团队">
                <select-team-input
                  :multi="true"
                  v-model="queryParam.teamId"
                  :teamType="0"
                  :tdlx="3"/>
<!--                <a-input placeholder="请输入费用所属团队" v-model="queryParam.teamId"></a-input>-->
              </a-form-item>

            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="用车类型">
                <j-dict-select-tag type="list" v-model="queryParam.useCarType" dictCode="using_type" placeholder="请选择用车类型" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="申请时间">
                <a-range-picker
                  :allowClear="false"
                  v-model="createTime"
                  style="width: 100%"
                  @change="createTimeChange"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('公车费用信息统计表')" :disabled="isDisabledAuth('erpReportCarCostInfo:export')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpReportCarCostInfo:import')">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpReportCarCostInfo:delete')"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:'180%'}"
        :components="draggableComponent"
        bordered
        rowKey="billNo"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="documentNo" slot-scope="text, record" @click="getDetail(record)">{{ text }}</a>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
            <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="edit"
                @click="handleEdit(record)"
                :disabled="isDisabledAuth('erpReportCarCostInfo:edit')"
        />
        <a-divider type="vertical"/>
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="delete"
                    :disabled="isDisabledAuth('erpReportCarCostInfo:delete')"/>
        </a-popconfirm>
        </span>
        <a slot="projectId" slot-scope="text, record" @click="onDetail(record.projectName)">{{ text }}</a>
      </a-table>
    </div>

<!--    <erp-report-car-cost-info-modal ref="modalForm" @ok="modalFormOk"></erp-report-car-cost-info-modal>-->
    <erp-car-using-modal ref="modalForm" @ok="modalFormOk"></erp-car-using-modal>

    <!-- 项目详情开始 -->
    <erp-project-report-modal  ref="prejectForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpReportCarCostInfoModal from './modules/ErpReportCarCostInfoModal'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectCarInfoInput from '@/views/scy/components/SelectCarInfoInput'
  import ErpCarUsingModal from '@/views/oa/erpcarusing/modules/ErpCarUsingModal'
  import { getAction } from '@/api/manage'
  import moment from 'moment'
  import SelectCarNumInput from '@/views/oa/carmaintenance/modules/SelectCarNumInput';
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'

  export default {
    name: 'ErpReportCarCostInfoList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpReportCarCostInfoModal,
      SelectTeamInput,
      SelectUserByDep,
      SelectCarNumInput,
      ErpCarUsingModal,
      SelectCarInfoInput,
      ErpProjectReportModal
    },
    data () {
      return {
        description: '公车费用信息统计表管理页面',

        columns:[],
        //列设置
        settingColumns:[],

        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'billNo_dictText',
            scopedSlots: { customRender: 'documentNo' },
            width: 150,
            ellipsis: true,
          },

          {
            title:'申请人',
            align:"center",
            dataIndex: 'proposer_dictText',
            width: 150,
            ellipsis: true,
          },
          {
            title:'申请部门',
            align:"center",
            dataIndex: 'proposerDeptId_dictText',
            width: 150,
            ellipsis: true,
          },
          {
            title:'申请时间',
            align:"center",
            dataIndex: 'applicationTime',
            width: 150,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'申请车辆',
            align:"center",
            dataIndex: 'applicationCar_dictText',
            width: 150,
            ellipsis: true,
          },
          {
            title:'预定时间',
            align:"center",
            dataIndex: 'presetTime',
            width: 150,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'还车时间',
            align:"center",
            dataIndex: 'carBackTime',
            width: 150,
            ellipsis: true,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'使用天数',
            align:"center",
            dataIndex: 'useDay',
            width: 150,
            ellipsis: true,
          },
          {
            title:'费用所属团队',
            align:"center",
            dataIndex: 'teamId_dictText',
            width: 150,
            ellipsis: true,
          },
          {
            title:'用车类型',
            align:"center",
            dataIndex: 'useCarType_dictText',
            width: 150,
            ellipsis: true,
          },

          {
            title:'项目名称',
            align:"center",
            scopedSlots: { customRender: 'projectId' },
            dataIndex: 'projectName_dictText',
            width: 150,
            ellipsis: true,
          },

          {
            title:'使用公里数',
            align:"center",
            dataIndex: 'useMileage',
            width: 150,
            ellipsis: true,
          },
          {
            title:'租金（元）',
            align:"center",
            dataIndex: 'rent',
            width: 150,
            ellipsis: true,
          },
          {
            title:'公里数费用（元）',
            align:"center",
            dataIndex: 'mileageCost',
            width: 150,
            ellipsis: true,
          },
          {
            title:'费用合计（元）',
            align:"center",
            dataIndex: 'costTotal',
            width: 150,
            ellipsis: true,
          }
        ],
        url: {
          list: "/api/erp/modules/workbench/report/erpReportCarCostInfo/list",
          exportXlsUrl: "/api/erp/modules/workbench/report/erpReportCarCostInfo/exportXls",
          importExcelUrl: "api/erp/modules/workbench/report/erpReportCarCostInfo/importExcel",
          queryCarUsingById:"/api/erp/erpcarusing/erpCarUsing/queryById",
          queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        },
        dictOptions:{},
        superFieldList:[],
        isorter: {
          column: 'applicationTime',
          order: 'desc'
        },
        queryParam: {
          createStartTime: moment().startOf('month').format("YYYY-MM-DD"),
          createEndTime: moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')
        },
        // createTime: [moment().startOf('month').format("YYYY-MM-DD"),moment(t, dateFormat).add(1, 'months').startOf('month').format('YYYY-MM-DD')],
        createTime: [moment().startOf('month').format("YYYY-MM-DD"),moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')]
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      customRow(record){},
      async getDetail(record) {
        let byId;
        await getAction(this.url.queryCarUsingById,{id: record.billNo}).then((res) => {
          if (res.success) {
            console.log('请求成功：结果为：',res.result)
            byId = res.result;
          }
        });
        this.$refs.modalForm.edit(byId);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
      },
      createTimeChange(date, dateString) {
        this.$set(this.queryParam, 'createStartTime', dateString[0] + ' 00:00:00')
          this.$set(this.queryParam, 'createEndTime', dateString[1] + ' 23:59:59')
      },
      searchReset() {
        // this.createTime[0] = ;
        // this.createTime[1] = ;
        // this.createTime = [moment().startOf('month').format("YYYY-MM-DD"),moment(t, dateFormat).add(1, 'months').startOf('month').format('YYYY-MM-DD')]
        this.queryParam = {
          createStartTime: moment().startOf('month').format("YYYY-MM-DD"),
          createEndTime: moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')
        }
        this.createTime = [moment().startOf('month').format("YYYY-MM-DD"),moment(moment().month(moment().month()).endOf('month').valueOf()).format('YYYY-MM-DD')]
        console.log('传递的时间参数为：',this.createTime)
        this.loadData(1)
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'billNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'proposer',text:'申请人',dictCode:''})
        fieldList.push({type:'date',value:'applicationTime',text:'申请时间'})
        fieldList.push({type:'string',value:'applicationCar',text:'申请车辆',dictCode:''})
        fieldList.push({type:'date',value:'presetTime',text:'预定时间'})
        fieldList.push({type:'string',value:'proposerdeptid',text:'申请部门',dictCode:''})
        fieldList.push({type:'string',value:'teamId',text:'费用所属团队',dictCode:''})
        fieldList.push({type:'string',value:'useCarType',text:'用车类型',dictCode:''})
        fieldList.push({type:'date',value:'carBackTime',text:'还车时间'})
        fieldList.push({type:'string',value:'projectName',text:'项目名称',dictCode:''})
        fieldList.push({type:'int',value:'useDay',text:'使用天数',dictCode:''})
        fieldList.push({type:'string',value:'useMileage',text:'使用公里数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'rent',text:'租金（元）',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'mileageCost',text:'公里数费用',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'costTotal',text:'费用合计',dictCode:''})
        this.superFieldList = fieldList
      },
      // 穿透项目底表
      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectReportById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.prejectForm.getDetail(model);
              that.$refs.prejectForm.title = '项目一览表';
            }
          })
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
